package cn.yq.share.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 007
 * @version V1.0
 * @Description:
 * @date 2018/11/20 18:35
 */
@Controller
public class TestController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @RequestMapping("/hello")
    public ModelAndView hello(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("test");
        modelAndView.addObject("name","可以");
        modelAndView.addObject("message","第一个");
        return modelAndView;
    }

//    @RequestMapping(value="/testController",produces = "text/html; charset=UTF-8")
    @RequestMapping(value="/testController",produces = "application/json; charset=UTF-8")
    public String test1(){
        Map map = new HashMap();
        map.put("crp","tianzhi");
        map.put("date","20181121");
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(map));
        System.out.println(jsonObject.toJSONString());
        System.out.println(jsonObject.toString());
       return jsonObject.toString();
    }

    @RequestMapping(value="/test2r",produces = "text/html; charset=UTF-8")
    public String test2(){
        logger.debug("调用接口test2r");
        Map map = new HashMap();
        map.put("crp","tianzhi");
        map.put("date","20181121");
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(map));
        return "";
    }
}
